package cn.updata.com.testupdata;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import java.io.File;

import cn.tinkerpatch.com.tinker.TinkerManager;

public class MainActivity extends AppCompatActivity {

    private static final String FILE_END=".apk";
    private String mPatchDir;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mPatchDir=getExternalCacheDir().getAbsolutePath()+"/tpatch/";
        File file=new File(mPatchDir);
        if(!file.exists()){
            file.mkdir();
            Toast.makeText(this, "文件夹不存在 创建 "+mPatchDir, Toast.LENGTH_SHORT).show();
        }
    }

    public void loadPath(View view){
        String patchName = getPatchName();
        toast("加载 "+patchName);
        TinkerManager.loadPath(patchName);
    }

    private String getPatchName(){
        return mPatchDir.concat("imooc").concat(FILE_END);
    }

    public void toastView(View view) {
        Toast.makeText(this, "8888888", Toast.LENGTH_SHORT).show();
    }
    public void toast(String str){
        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    }

    public void jumpActivity(View view) {
        startActivity(new Intent(this,TestActivity.class));
    }
}
